
import { invoke } from '@tauri-apps/api/core';
import { ComparsionOperator, DeleteCondition, DeleteOptions, QueryCondition, QueryExtention, QueryOptions, UpdateCondition, UpdateOptions } from '../types';
import optionsWrap from '@/components/datasets/create/website/base/options-wrap';
import { DataSource } from '@/services/data-source';
import { APPLICATION_CONVERSATION_MESSAGE_CLASS_IDENTIFIER } from '@/services/constants';
import { dsFind, dsInsert } from '../datasource';
import { appDatasource } from './application';

export interface ApplicationConversationMessage {
    id?: number,
    conversation_identifier: string,
    identifier: string,
    parent_identifier: string,
    query: string,
    answer: string,
    files?: string,
    feedback?: string,
    retriever_resources?: string,
    inputs?: string[],
    status: 'normal',
    description?: string,
}

export const appFetchConversationMessages = async (identifier: string, isInstalled: boolean, conversationId: string): Promise<any[]> => {

    let data: any = await dsFind(await appDatasource(identifier, isInstalled), APPLICATION_CONVERSATION_MESSAGE_CLASS_IDENTIFIER, {
        attributes: [{
            name: 'conversation_identifier',
            operator: ComparsionOperator.Equal,
            value: conversationId
        }]
    });
    data.data = data.data.map((item) => { return { ...item, id: item.identifier, } })
    console.log(data);
    return data;
}

export const appInsertConversationMessage = async (identifier: string, isInstalled: boolean, item: ApplicationConversationMessage): Promise<any[]> => {
    console.log('appInsertConversationMessage', identifier, isInstalled, item);

    let data: any = await dsInsert(await appDatasource(identifier, isInstalled), APPLICATION_CONVERSATION_MESSAGE_CLASS_IDENTIFIER, item);

    console.log(data);
    return data;
}



export default {}